<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <div>
        <button onclick="doAxiosAjaxGet()">axios.get(...)</button><br>
        <button onclick="doAxiosAjaxPost()">axios.post(...)</button>
        <button onclick="doAxiosAjaxPostJSON()">axios.postJSON(...)</button>
    </div>
    <div class="result"></div>
<script src="js/axios.min.js"></script>
<script>
    function doAxiosAjaxPostJSON() {
        //1,url
        let url="http://localhost/doPostJSON";
        //2,params
        // let params="msg=hello axios";
        let params={"msg":"hello axios"};//JSON字符串
        //3,send ajax post request
        axios.post(url,params)
            .then(function (result) {
                console.log(result);
                document.querySelector(".result").innerHTML=JSON.stringify(result.data)/*result.data*/;
            })
            .catch(function (error) {
                console.log(error);
            });
    }
    function doAxiosAjaxPost() {
        //1,url
        let url="http://localhost/doPost";
        //2,params
        let params="msg=hello axios";
        // let params={"msg":"hello axios"};
        //3,send ajax post request
        axios.post(url,params)
            .then(function (result) {
                console.log(result);
                document.querySelector(".result").innerHTML=JSON.stringify(result.data)/*result.data*/;
            })
            .catch(function (error) {
                console.log(error);
            });
    }
    function doAxiosAjaxGet(){
        //1,url
        let url="http://localhost/doGet";
        //2,params
        let params={params: {"msg":"hello axios"}};
        //3,send ajax get request
        axios.get(url,params)
            .then(function (result) {
                console.log(result);
                document.querySelector(".result").innerHTML=JSON.stringify(result.data)/*result.data*/;
                })
            .catch(function (error) {
                console.log(error);
            });
    }
</script>
</body>
</html>